import org.junit.Test;

import java.io.UnsupportedEncodingException;
import java.util.Comparator;

/**
 * IDEA的Debug使用
 *
 * @author wx
 * @create 2019-12-12 19:55
 */
public class IDEADebug {
    //以下代码输出
//    String str = new String("good");
//    char[] ch = { 't', 'e', 's', 't' };
//    public void change(String str, char ch[]) {
//        str = "test ok";
//        ch[0] = 'b'; }
//    public static void main(String[] args) {
//        IDEADebug ex = new IDEADebug();
//        ex.change(ex.str, ex.ch);
//        System.out.print(ex.str + " and ");//
//        System.out.println(ex.ch); //good and best
//    }


    @Test
    public void myDebug() {
        String str = null;
        StringBuffer sb = new StringBuffer();
        sb.append(str);//不会报空指针

        System.out.println("sb.length() = " + sb.length());//4
        System.out.println(sb);//"null" 不是null!

        StringBuffer sb2 = new StringBuffer(str);//空指针
        System.out.println(sb2);

    }

    @Test
    public void strMethods() throws UnsupportedEncodingException {//字符串常用方法
        //正则
        String str = "12hello34world5java7891mysql456";
//把字符串中的数字替换成,，如果结果中开头和结尾有，的话去掉
        String string = str.replaceAll("\\d+", ",").replaceAll("^,|,$", "");
        System.out.println(string);

        //字符串和字节数据之间的转换
        str = "中";
        System.out.println(str.getBytes("ISO8859-1").length);// -128~127
        System.out.println(str.getBytes("GBK").length);
        System.out.println(str.getBytes("UTF-8").length);
        System.out.println(new String(str.getBytes("ISO8859-1"),
                "ISO8859-1"));// 乱码，表示不了中文
        System.out.println(new String(str.getBytes("GBK"), "GBK"));
        System.out.println(new String(str.getBytes("UTF-8"), "UTF-8"));


        String a = "123";
        String b = "123";
        String c = new String("123");
        String d = new String("123");
        System.out.println(a.equals(b));//true
        System.out.println(a == b);  //true
        System.out.println(c.equals(d)); //true
        System.out.println(c == d);  //false
        System.out.println(a.equals(c)); //true
        System.out.println(a == c); //false

        String.valueOf(4);
//        Integer.parseInt()

        double random = Math.random();
        Comparator objectComparator = new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                return 0;
            }
        };

        for (Thread.State value : Thread.State.values()) {
            System.out.println("value = " + value);
        }
    }
}
